home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AppsToGo / DTS.Draw / TOvalObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  6.1 KB  |  235 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        TOvalObj.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1992-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* See the files "=How to write your app" and "=Using TreeObj.c" for information
  20. ** on this function. */
  21.  
  22. /* This file implements the messages for the oval object.  Many of the messages
  23. ** can be handled by the rect object, as they deal with a rect structure.  Only
  24. ** a few of them are oval-specific. */
  25.  
  26. /* It would seem that you would want a custom hit-test message handler here, but
  27. ** the rect object first checks to see if the hit is within the bounding box of
  28. ** the object, and if so, it then calls the object to return the region.  This
  29. ** allows the rect object to generically handle hit-testing. */
  30.  
  31.  
  32.  
  33. /*****************************************************************************/
  34.  
  35.  
  36.  
  37. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  38. #include "App.protos.h"        /* Get the prototypes for the application.        */
  39.  
  40. #ifndef __OSEVENTS__
  41. #include <OSEvents.h>
  42. #endif
  43.  
  44. #ifndef __OSUTILS__
  45. #include <OSUtils.h>
  46. #endif
  47.  
  48. #ifndef __QUICKDRAW__
  49. #include <Quickdraw.h>
  50. #endif
  51.  
  52. #ifndef __TREEOBJ2__
  53. #include "TreeObj2.h"
  54. #endif
  55.  
  56. #ifndef __UTILITIES__
  57. #include "Utilities.h"
  58. #endif
  59.  
  60.  
  61.  
  62. /*****************************************************************************/
  63.  
  64.  
  65.  
  66. static OvalObjPeek    *gMWERKSDebug;
  67.     /* For Metroweks debugging of AppsToGo "objects", you need an instance of the
  68.     ** same type you wish to view it in the debugger.  Now we have an instance. */
  69.  
  70.  
  71.  
  72. /*****************************************************************************/
  73. /*****************************************************************************/
  74.  
  75. #ifdef applec
  76. #pragma segment DTSDrawSeg2
  77. #endif
  78.  
  79. /*****************************************************************************/
  80. /*****************************************************************************/
  81.  
  82.  
  83.  
  84. long    TOvalObj(TreeObjHndl hndl, short message, long data)
  85. {
  86.     Rect        rct;
  87.     RgnHandle    rgn, accumRgn;
  88.     short        h, w;
  89.     RGBColor    rgb, rgb2;
  90. #if VH_VERSION
  91.     char        *cptr;
  92. #endif
  93.  
  94.     switch (message) {
  95.         case INITMESSAGE:
  96.         case FREEMESSAGE:
  97.         case COPYMESSAGE:
  98.         case UNDOMESSAGE:
  99.         case CONVERTMESSAGE:
  100.         case FREADMESSAGE:
  101.         case FWRITEMESSAGE:
  102.         case HREADMESSAGE:
  103.         case HWRITEMESSAGE:
  104.         case HITTESTMESSAGE:
  105.         case GETOBJRECTMESSAGE:
  106.         case SETOBJRECTMESSAGE:
  107.         case SECTOBJRECTMESSAGE:
  108.         case GETBBOXMESSAGE:
  109.         case CLICKMESSAGE:
  110.         case KEYMESSAGE:
  111.         case SETSELECTMESSAGE:
  112.         case GETSELECTMESSAGE:
  113.         case SIZEMESSAGE:
  114.         case COMPAREMESSAGE:
  115.             return(TRectObj(hndl, message, data));
  116.             break;
  117.  
  118.         case GETRGNMESSAGE:
  119.             rgn      = NewRgn();
  120.             accumRgn = (RgnHandle)data;
  121.             if (accumRgn)
  122.                 if (GetHandleSize((Handle)accumRgn) > 10000)
  123.                     return((long)rgn);
  124.             OpenRgn();
  125.             rct = mDerefOval(hndl)->oval;
  126.             FrameOval(&rct);
  127.             CloseRgn(rgn);
  128.             if (accumRgn)
  129.                 UnionRgn(rgn, accumRgn, accumRgn);
  130.             return((long)rgn);
  131.             break;
  132.  
  133.         case DRAWMESSAGE:
  134.             rct = mDerefOval(hndl)->oval;
  135.             h   = mDerefCommon(hndl)->penHeight;
  136.             w   = mDerefCommon(hndl)->penWidth;
  137.             PenSize(w, h);
  138.             switch (data) {
  139.                 case DRAWOBJ:
  140.                     if (gQDVersion)
  141.                         GetForeColor(&rgb);
  142.                     ForeColor(whiteColor);
  143.                     if (gQDVersion) {
  144.                         rgb2 = mDerefOval(hndl)->contentColor;
  145.                         RGBForeColor(&rgb2);
  146.                     }
  147.                     PaintOval(&rct);
  148.                     ForeColor(blackColor);
  149.                     if (gQDVersion) {
  150.                         rgb2 = mDerefOval(hndl)->borderColor;
  151.                         RGBForeColor(&rgb2);
  152.                     }
  153.                     FrameOval(&rct);
  154.                     if (gQDVersion)
  155.                         RGBForeColor(&rgb);
  156.                     break;
  157.                 case ERASEOBJ:
  158.                     EraseOval(&rct);
  159.                     break;
  160.                 case DRAWSELECT:
  161.                     TRectObj(hndl, message, data);
  162.                     break;
  163.                 case DRAWGHOST:
  164.                     PenMode(patXor);
  165.                     FrameOval(&rct);
  166.                     break;
  167.                 case DRAWMASK:
  168.                     FillOval(&rct, (ConstPatternParam)&qd.black);
  169.                     break;
  170.             }
  171.             PenNormal();
  172.             break;
  173.  
  174.         case PRINTMESSAGE:
  175.             TOvalObj(hndl, DRAWMESSAGE, DRAWOBJ);
  176.             break;
  177.  
  178. #if VH_VERSION
  179.         case VHMESSAGE:
  180.             cptr = ((VHFormatDataPtr)data)->data;
  181.             ccatchr(cptr, 13, 2);
  182.             ccat   (cptr, "$10: TOvalObj:");
  183.             ccatchr(cptr, 13, 1);
  184.             ccat   (cptr, "  $00: selected     = ");
  185.             ccatdec(cptr, mDerefOval(hndl)->selected);
  186.             ccatchr(cptr, 13, 1);
  187.             rct = mDerefOval(hndl)->oval;
  188.             ccat      (cptr, "  $02: oval         = ($");
  189.             ccatpadhex(cptr, 0, 4, 4, rct.top);
  190.             ccat      (cptr, ",$");
  191.             ccatpadhex(cptr, 0, 4, 4, rct.left);
  192.             ccat      (cptr, ",$");
  193.             ccatpadhex(cptr, 0, 4, 4, rct.bottom);
  194.             ccat      (cptr, ",$");
  195.             ccatpadhex(cptr, 0, 4, 4, rct.right);
  196.             ccat      (cptr, ")");
  197.             ccatchr   (cptr, 13, 1);
  198.             ccat      (cptr, "  $0A: penHeight    = ");
  199.             ccatdec   (cptr, mDerefOval(hndl)->penHeight);
  200.             ccatchr   (cptr, 13, 1);
  201.             ccat      (cptr, "  $0C: penWidth    = ");
  202.             ccatdec   (cptr, mDerefOval(hndl)->penWidth);
  203.             ccatchr   (cptr, 13, 1);
  204.             ccat      (cptr, "  $0E: borderColor  = ($");
  205.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.red);
  206.             ccat      (cptr, ",$");
  207.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.green);
  208.             ccat      (cptr, ",$");
  209.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.blue);
  210.             ccat      (cptr, ")");
  211.             ccatchr   (cptr, 13, 1);
  212.             ccat      (cptr, "  $1$: content      = ($");
  213.             ccatdec   (cptr, mDerefOval(hndl)->content);
  214.             ccatchr   (cptr, 13, 1);
  215.             ccat      (cptr, "  $16: contentColor = ($");
  216.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.red);
  217.             ccat      (cptr, ",$");
  218.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.green);
  219.             ccat      (cptr, ",$");
  220.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.blue);
  221.             ccat      (cptr, ")");
  222.             return(true);
  223.             break;
  224. #endif
  225.  
  226.         default:
  227.             break;
  228.     }
  229.  
  230.     return(noErr);
  231. }
  232.  
  233.  
  234.  
  235.